home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- NewApp.c
-
- DESCRIPTION
- Contains code for all of our message overrides except the old-application
- compatibility, custom I/O, and custom buffering ones.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Created from the shell of a hollowed-out
- ImageWriter driver.
-
- NOTE: Relevant goodies are listed in MPW's "Mark" menu.
-
- */
-
- #include "CommonDefines.h"
-
-
- /* -----------------------------------------------------------------------
-
- SD_RasterDataIn is an override of gxRasterDataIn. It simply takes the
- bitmap data passed to us, and sends it to the "device" using
- Send_GXBufferData. For this driver, we're being passed 32-bit XRGB
- data (where "X" indicates an unused alpha byte), stripping off the
- unused byte, and sending it to gxBufferData as RGB data.
-
- If we find that we've moved over blank lines, we call WriteBlankLines
- to send RGB bands of white to gxBufferData. If your device supports
- it, it is far more economical to skip the white space, rather than
- image it.
-
- ----------------------------------------------------------------------- */
-
- OSErr SD_RasterDataIn (gxOffscreenHdl hOffscreen, gxRectangle *bandRect, gxRectangle *dirtyRect)
- {
- OSErr anErr;
- char lockState;
- gxBitmap *pBitmap;
- unsigned char *XRGBDataPtr, *RGBDataPtr, *scanStart;
- long rowNum, colNum, amtToWrite, numBlankLinesToDo;
- Ptr baseAddr;
- DriverGlobalsHdl drvrGlobalsHdl = GetDriverGlobals();
-
- #pragma unused(dirtyRect);
-
- // Update the status display to indicate that we're sending data
- // to the "printer."
-
- anErr = GXReportStatus(kTransmissionStatID, kSendingPartStatIdx);
- require(anErr == noErr, ReportStatus_Failed);
-
-
- // Write some blank lines if we need to.
-
- numBlankLinesToDo = (bandRect->top >>16) - (*drvrGlobalsHdl)->lastYPos;
-
- if (numBlankLinesToDo > 0)
- {
- anErr = WriteBlankLines(numBlankLinesToDo, bandRect);
- nrequire(anErr, WriteBlankLines_Failed);
- }
-
- // Make sure the offscreen bitmap is locked down, and then repackage the
- // data. To save space, we're converting the XRGB data to RGB data in
- // the same imaging buffer that was passed to us.
-
- lockState = HGetState((Handle) hOffscreen);
- HLockHi((Handle) hOffscreen);
-
- pBitmap = &(*hOffscreen)->thePlanes[0].theBits;
- baseAddr = RGBDataPtr = XRGBDataPtr = (unsigned char *) pBitmap->image + ((bandRect->left >>16) * 4);
-
-
- // Convert all data in this raster bitmap to 24-bit RGB. XRGBData
- // points to the next byte of unconverted data, and RGBDataPtr
- // points to the next place to store the converted RGB data.
-
- for (rowNum = (bandRect->top >>16); rowNum < (bandRect->bottom >>16); rowNum++)
- {
- scanStart = XRGBDataPtr;
-
- for (colNum = (bandRect->left >>16); colNum < (bandRect->right >>16); colNum++)
- {
- ++XRGBDataPtr; // skip those dang alphas!
- *RGBDataPtr = *XRGBDataPtr; // copy Red component
- ++RGBDataPtr;
- ++XRGBDataPtr;
- *RGBDataPtr = *XRGBDataPtr; // copy Green component
- ++RGBDataPtr;
- ++XRGBDataPtr;
- *RGBDataPtr = *XRGBDataPtr; // copy Blue component
- ++RGBDataPtr;
- ++XRGBDataPtr;
- }
-
- if (rowNum == (bandRect->top >>16)) // 1st row? Store some things for later.
- {
- (*drvrGlobalsHdl)->pixMapRowBytes = (long) XRGBDataPtr - (long) baseAddr;
- (*drvrGlobalsHdl)->pixMapBounds.bottom += (bandRect->bottom >>16) - (bandRect->top >>16);
- (*drvrGlobalsHdl)->pixMapBounds.right = (bandRect->right >>16) - (bandRect->left >>16);
- }
-
- // Bump XRGBDataPtr to the start of the next scan line.
- XRGBDataPtr = scanStart + (pBitmap->rowBytes & 0x7FFF);
- }
-
- // Write out the data for this band.
-
- amtToWrite = (long) RGBDataPtr - (long) baseAddr;
- anErr = Send_GXBufferData(baseAddr, amtToWrite, gxNoBufferOptions);
-
- // Reset the handle's lock on the way out, and update our
- // lastYPos variable.
-
- HSetState((Handle) hOffscreen, lockState);
-
- WriteBlankLines_Failed:
- ReportStatus_Failed:
- (*drvrGlobalsHdl)->lastYPos = (bandRect->bottom >>16) +1;
-
- return anErr;
- }
-
-
- /* -----------------------------------------------------------------------
-
- WriteBlankLines is a routine used to add blank lines to our output.
- We use this to add "skipped over" lines to our output from
- SD_RasterDataIn. Since we're printing to a file, we need to add the
- white space as bands of white data.
-
- ----------------------------------------------------------------------- */
-
- OSErr WriteBlankLines(long numBlankLinesToDo, gxRectangle *bandRect)
- {
- OSErr anErr = noErr;
- long line, aByte, lineLength;
- unsigned char *blankLine, *whichByte;
-
- // Record some "blank lines" in our file. NOTE: This assumes we output 24-bit RGB data.
-
- if (numBlankLinesToDo > 0)
- {
- // Create a pointer to hold one white (0xFF, 0xFF, 0xFF…) line.
-
- lineLength = 3 * ((bandRect->right >>16) - (bandRect->left >> 16));
- blankLine = NewPtrSys(lineLength);
- nrequire((anErr = MemError()), NewPtrSys_Failed);
-
- // Make it white.
-
- for (aByte = 0, whichByte = blankLine; aByte < lineLength; aByte++, whichByte++)
- *whichByte = 0xFF;
-
- // Write it to the file as many times as necessary, then dispose of our pointer.
-
- for (line = 0; line < numBlankLinesToDo; line++)
- anErr = Send_GXBufferData((Ptr) blankLine, lineLength, gxNoBufferOptions);
-
- DisposePtr(blankLine);
- }
-
- NewPtrSys_Failed:
- return anErr;
- }
-